let api = [];
const apiDocListSize = 1
api.push({
    name: 'default',
    order: '1',
    list: []
})
api[0].list.push({
    alias: 'ExportDataController',
    order: '1',
    link: '数据导出',
    desc: '数据导出',
    list: []
})
api[0].list[0].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/batteryDetails/export',
    methodId: 'a6bcff18e5f8df2d637c8ce8b067cb2f',
    desc: '电池充放电详情数据导出接口',
});
api[0].list[0].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/batteryComprehensive/export',
    methodId: 'f5097cbea9eb15eab46cafaba8f951b1',
    desc: '电池综合列表数据导出接口',
});
api[0].list[0].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacityDetailExport',
    methodId: 'e5ab8d62b289d0bbeeb894d0678a4023',
    desc: '电池容量详情数据导出接口',
});
api[0].list[0].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacityStatusExport',
    methodId: '0a6d4cc34b922330782917446b9ce8b5',
    desc: '电池放电容量数据导出接口',
});
api[0].list.push({
    alias: 'StepSettingsController',
    order: '2',
    link: '工步方案接口',
    desc: '工步方案接口',
    list: []
})
api[0].list[1].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepAdd',
    methodId: 'fb306972e3fd3eb1b0bcbbfe4ff08fd6',
    desc: '工步方案新增接口',
});
api[0].list[1].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepModify',
    methodId: 'bec014a78ffc85d761b22da16235f69d',
    desc: '工步方案修改接口',
});
api[0].list[1].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepDel',
    methodId: '1a5ddc73d5013306b342e4cd5263482b',
    desc: '工步方案删除接口',
});
api[0].list.push({
    alias: 'ServiceShutdownAndReStartController',
    order: '3',
    link: '服务关闭及重启接口',
    desc: '服务关闭及重启接口',
    list: []
})
api[0].list[2].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/shutdown',
    methodId: 'b34e204f4d2849ac979b2cea3a4892e1',
    desc: '',
});
api[0].list[2].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/restart',
    methodId: 'dc058272fe06f611cc9e13b7aedd4be8',
    desc: '',
});
api[0].list.push({
    alias: 'StepIssuedController',
    order: '4',
    link: '指令下发接口',
    desc: '指令下发接口',
    list: []
})
api[0].list[3].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepIssued',
    methodId: 'd3ad7d7b06cfa8d39e5e96590edd87d1',
    desc: '执行工步指令下发接口',
});
api[0].list[3].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepIssuedSingle',
    methodId: '80c54c56ac4998eea9522ec3ecb4e00e',
    desc: '单个通道执行工步指令下发接口',
});
api[0].list.push({
    alias: 'LoginController',
    order: '5',
    link: '用户接口',
    desc: '用户接口',
    list: []
})
api[0].list[4].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/logIn',
    methodId: '47e41ad8acdc834a47139f7e300195ba',
    desc: '用户登录',
});
api[0].list[4].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/logOut',
    methodId: 'a2f60a1e5fcdbe87f2a386f23871c08f',
    desc: '用户退出',
});
api[0].list[4].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/userAdd',
    methodId: '1e3356c580584b3d4480e8b40e80aeb4',
    desc: '新增用户',
});
api[0].list[4].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/userDel',
    methodId: '654dc595d260ccbf61877b919edd4609',
    desc: '用户删除',
});
api[0].list.push({
    alias: 'QueryDataController',
    order: '6',
    link: '数据查询接口',
    desc: '数据查询接口',
    list: []
})
api[0].list[5].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/wholeStepIssued/query',
    methodId: 'f387aa6e4d40cbd69148ba42c934b465',
    desc: '整体工艺方案执行情况查询接口',
});
api[0].list[5].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/singleStepIssued/query',
    methodId: 'b98f3af1e6b1345049d189a1ca7c4a19',
    desc: '单个电池工艺方案执行情况查询接口',
});
api[0].list[5].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/lastRealTimeData/query',
    methodId: '8c788787861c026b4a505cbbb4c4948c',
    desc: '电池实时数据查询接口(工步执行中首页数据展示数据)',
});
api[0].list[5].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/batteryDetails/query',
    methodId: 'c680f8e9d732df8e8b973a090d5a7e76',
    desc: '每个电芯充放电详情数据查询接口(单个电芯电流电压曲线图)',
});
api[0].list[5].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/batteryDetails/queryHistory',
    methodId: 'eecc507b6739f4f3ec85699f36536405',
    desc: '每个电芯充放电详情历史数据查询接口(单个电芯电流电压曲线历史数据查询)',
});
api[0].list[5].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/batteryComprehensiveList/query',
    methodId: '66041e3b40dbaeaa429685c8dc85795f',
    desc: '电池综合列表数据查询接口',
});
api[0].list[5].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacity/stats',
    methodId: '5c291246fb46d7ee9fa3a55593091b8e',
    desc: '电池容量级别统计数据查询接口(已弃用，返回数据为空)',
});
api[0].list[5].list.push({
    order: '8',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacity/details',
    methodId: '046fa0b086e758fcea324601a139b1a7',
    desc: '电池分容容量详情数据查询接口(已弃用，返回数据为空)',
});
api[0].list[5].list.push({
    order: '9',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/executingStep/query',
    methodId: '1ab57af1adc4c5795f83eb49370eb06f',
    desc: '正在执行的工步指令数据查询接口(已弃用，返回数据为空)',
});
api[0].list[5].list.push({
    order: '10',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/stepQuery',
    methodId: '6f68dfa66a8b8c010b3e4601a0c160f2',
    desc: '工步设置方案查询接口',
});
api[0].list[5].list.push({
    order: '11',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/schemeQuery',
    methodId: 'db3041904265f2d2e2aeed3154e1148c',
    desc: '分容设置方案查询接口',
});
api[0].list[5].list.push({
    order: '12',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/cabinetNoQuery',
    methodId: '0ab0c50b64ee25bc45f68c27499eabba',
    desc: '可下发指令机柜号查询接口',
});
api[0].list[5].list.push({
    order: '13',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/offlineDeviceQuery',
    methodId: '5aabcb055f8574bb6ecbea1052423fb0',
    desc: '离线设备信息查询接口',
});
api[0].list[5].list.push({
    order: '14',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/cabinetVersionQuery',
    methodId: '851ef09316d99f1c36fd0fd95de8590c',
    desc: '机柜程序版本查询接口',
});
api[0].list[5].list.push({
    order: '15',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/localDeviceCapacityQuery',
    methodId: 'b06210a9aa37793cc9893c13363dbfd9',
    desc: '本地设备分容结果查询接口',
});
api[0].list[5].list.push({
    order: '16',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/history/dbFile/query',
    methodId: '2714f61a5b00f6fa799b875971cb2a74',
    desc: '历史数据数据库文件查询接口(已弃用，返回数据为空)',
});
api[0].list[5].list.push({
    order: '17',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/single/batteryCell/query',
    methodId: '51d47563e582c4406200e73633923b37',
    desc: '实时曲线单个电芯最后一条电压电流数据查询接口',
});
api[0].list[5].list.push({
    order: '18',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/queryBatchNo',
    methodId: 'e4ff37a48f183abee914dc9b36fb5a4f',
    desc: '所有批次号查询接口',
});
api[0].list[5].list.push({
    order: '19',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/queryStatus',
    methodId: 'a1443d00aa737052b0b4717b0da84c3c',
    desc: '所有机柜状态查询接口',
});
api[0].list[5].list.push({
    order: '20',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/queryCapacityStatus',
    methodId: '6915c520bfcfff1c9002e62932aaf364',
    desc: '电池放电容量数据查询接口',
});
api[0].list[5].list.push({
    order: '21',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/queryCapacityDetail',
    methodId: '3296d3ed45929b18dd0d87609f175606',
    desc: '电池容量详情数据查询接口',
});
api[0].list.push({
    alias: 'SettingController',
    order: '7',
    link: '电池分容接口',
    desc: '电池分容接口',
    list: []
})
api[0].list[6].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/ipSetting',
    methodId: '00da8c690886b66727a1b901560a24a9',
    desc: '分容柜网络IP地址设置接口',
});
api[0].list[6].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacitySchemeAdd',
    methodId: 'b36b912a00089f8b20c81e2f1938462a',
    desc: '分容设置方案新增接口',
});
api[0].list[6].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacitySchemeModify',
    methodId: 'bef90958e176e3b885048dff49b52b9a',
    desc: '分容设置方案修改接口',
});
api[0].list[6].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/capacitySchemeDel',
    methodId: '5f7d3c4ed1ddceee7609a4f514d70cea',
    desc: '分容设置方案删除接口',
});
api[0].list[6].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/localDeviceCapacityIssued',
    methodId: 'd58a1567695202945d12cd9b796d0075',
    desc: '本地分容结果查询指令下发接口',
});
api[0].list[6].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://localhost:14885/api/cabinet/history/dbFile/switch',
    methodId: 'cffed9db76f6447f5f0ecacfc6654299',
    desc: '历史数据库选择切换接口(已弃用)',
});
api[0].list.push({
    alias: 'error',
    order: '8',
    link: 'error_code_list',
    desc: '错误码列表',
    list: []
})
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code === 13) {
        const search = document.getElementById('search');
        const searchValue = search.value.toLocaleLowerCase();

        let searchGroup = [];
        for (let i = 0; i < api.length; i++) {

            let apiGroup = api[i];

            let searchArr = [];
            for (let i = 0; i < apiGroup.list.length; i++) {
                let apiData = apiGroup.list[i];
                const desc = apiData.desc;
                if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                    searchArr.push({
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        alias: apiData.alias,
                        list: apiData.list
                    });
                } else {
                    let methodList = apiData.list || [];
                    let methodListTemp = [];
                    for (let j = 0; j < methodList.length; j++) {
                        const methodData = methodList[j];
                        const methodDesc = methodData.desc;
                        if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                            methodListTemp.push(methodData);
                            break;
                        }
                    }
                    if (methodListTemp.length > 0) {
                        const data = {
                            order: apiData.order,
                            desc: apiData.desc,
                            link: apiData.link,
                            alias: apiData.alias,
                            list: methodListTemp
                        };
                        searchArr.push(data);
                    }
                }
            }
            if (apiGroup.name.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchGroup.push({
                    name: apiGroup.name,
                    order: apiGroup.order,
                    list: searchArr
                });
                continue;
            }
            if (searchArr.length === 0) {
                continue;
            }
            searchGroup.push({
                name: apiGroup.name,
                order: apiGroup.order,
                list: searchArr
            });
        }
        let html;
        if (searchValue === '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchGroup,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            let $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiGroups, liClass, display) {
    let html = "";
    if (apiGroups.length > 0) {
        if (apiDocListSize === 1) {
            let apiData = apiGroups[0].list;
            let order = apiGroups[0].order;
            for (let j = 0; j < apiData.length; j++) {
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#' + apiData[j].alias + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                html += '<ul class="sectlevel2" style="'+display+'">';
                let doc = apiData[j].list;
                for (let m = 0; m < doc.length; m++) {
                    let spanString;
                    if (doc[m].deprecated === 'true') {
                        spanString='<span class="line-through">';
                    } else {
                        spanString='<span>';
                    }
                    html += '<li><a href="#' + doc[m].methodId + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                }
                html += '</ul>';
                html += '</li>';
            }
        } else {
            for (let i = 0; i < apiGroups.length; i++) {
                let apiGroup = apiGroups[i];
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_'+apiGroup.order+'_' + apiGroup.name + '">' + apiGroup.order + '.&nbsp;' + apiGroup.name + '</a>';
                html += '<ul class="sectlevel1">';

                let apiData = apiGroup.list;
                for (let j = 0; j < apiData.length; j++) {
                    html += '<li class="'+liClass+'">';
                    html += '<a class="dd" href="#' + apiData[j].alias + '">' +apiGroup.order+'.'+ apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                    html += '<ul class="sectlevel2" style="'+display+'">';
                    let doc = apiData[j].list;
                    for (let m = 0; m < doc.length; m++) {
                       let spanString;
                       if (doc[m].deprecated === 'true') {
                           spanString='<span class="line-through">';
                       } else {
                           spanString='<span>';
                       }
                       html += '<li><a href="#' + doc[m].methodId + '">'+apiGroup.order+'.' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                   }
                    html += '</ul>';
                    html += '</li>';
                }

                html += '</ul>';
                html += '</li>';
            }
        }
    }
    return html;
}